****APPENDIX TABLE E1-E2****

cd "$main_dir/output/tables/appendix_e"

global basic 	marital edu
global econ	    employment_status occupation income imputed_income
global design 	survey_year age language
global polit    ideology party_member

//--------------------------------------------------------
//Create Table E1
//--------------------------------------------------------

clear
use "$data_dir/clean/shp_final_panel.dta"

gen total_obs = 1

tab sex, gen(sex_dummy)
tab edu, gen(edu_dummy)
tab marital, gen(marital_dummy)

cap drop sex_dummy1 sex_dummy4
rename sex_dummy2 male
rename sex_dummy3 female

cap drop edu_dummy1 edu_dummy5
rename edu_dummy2 primary
rename edu_dummy3 secondary
rename edu_dummy4 tertiary

rename marital_dummy1 married
rename marital_dummy2 not_married

collapse (sum) total_obs (mean) trust_fed_govt_med trust_others_med male female primary secondary tertiary married not_married, by(cohort)

drop if cohort=="" | cohort=="1900s" | cohort=="2000s"

local varlist trust_fed_govt_med trust_others_med male female primary secondary tertiary married not_married
foreach var of local varlist {
	format `var' %5.0g
}

export delimited using "table_e1.csv", replace

//--------------------------------------------------------
//Create Table E2
//--------------------------------------------------------

clear
use "$data_dir/clean/shp_final_panel.dta"

gen dummy = 1 if trust_fed_govt_med!=.
bys idpers: egen total_obs = total(dummy)

xtset idpers survey_year

cap drop sample income_sample
gen sample = 1 if live_switz==1 & total_obs>4 & total_obs!=. & age>=15 & age!=.

summ wdisaster_1 if sample==1, de
scalar disaster = r(p99)

cap drop wwinsz_disaster_1
gen wwinsz_disaster_1 = wdisaster_1
replace wwinsz_disaster_1 = `=disaster' if wdisaster_1>`=disaster' & `=disaster'!=.

qui reghdfe trust_fed_govt_med wgrowth_rate_1 if sample==1, absorb(canton $basic $design $econ $polit idpers) cluster(idhous yob)
keep if e(sample)==1

keep trust_fed_govt_med trust_others_med wgrowth_rate_1 wincome_growth_1 winflation_1 wstock_return_1 wpretax_income_top10_1 wpretax_income_top1_1 wgrowth_rate_1 wunemployment_rate_1 sd_inflation wprop_unrest_1 wprop_affect_epidemic_1 wbank_crisis_1 fy_growth_rate preyob_growth_rate_5 preyob_growth_rate_10 preyob_growth_rate_15 wgrowth_shock_1 wwinsz_disaster_1 wacceleration_1
order trust_fed_govt_med trust_others_med wgrowth_rate_1 wincome_growth_1 winflation_1 wstock_return_1 wpretax_income_top10_1 wpretax_income_top1_1 wgrowth_rate_1 wunemployment_rate_1 sd_inflation wprop_unrest_1 wprop_affect_epidemic_1 wbank_crisis_1 fy_growth_rate preyob_growth_rate_5 preyob_growth_rate_10 preyob_growth_rate_15 wgrowth_shock_1 wwinsz_disaster_1 wacceleration_1

outreg2 using table_e2, sum(log) replace


